/**
 * 
 */
package com.cqan.service.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.cqan.dao.BaseDao;
import com.cqan.orm.Page;
import com.cqan.orm.PropertyFilter;
import com.cqan.orm.PropertyFilter.MatchType;
import com.cqan.service.EntityService;


/**
 * @author slaton
 *
 * 下午05:15:41
 */
public abstract class EntityServiceImpl<T, PK extends Serializable, EntityDao extends BaseDao<T, PK>> implements EntityService<T,PK> {

	protected EntityDao entityDao;

	@Override
	public void add(T t) {
		
		entityDao.saveEntity(t);
	}

	@Override
	public void delete(PK id) {
		
		entityDao.delete(id);
	}


	@Override
	public void delete(List<PK> ids) {
		
		entityDao.delete(ids);
	}

	
	@Override
	public T get(PK id) {
		
		return entityDao.get(id);
	}


	@Override
	public Page<T> getAll(Page<T> page) {
		
		return entityDao.getAll(page);
	}


	@Override
	public List<T> getAll() {
		
		return entityDao.getAll();
	}


	@Override
	public List<T> getList(List<PropertyFilter> filters) {
		
		return entityDao.find(filters);
	}

	@Override
	public Page<T> search(Page<T> page, List<PropertyFilter> filters) {
		
		return entityDao.findPage(page, filters);
	}

	
	@Override
	public Page<T> search(Page<T> page, PropertyFilter filter) {
		
		return entityDao.findPage(page, filter);
	}

	@Override
	public void update(T t) {
		
		entityDao.saveEntity(t);
	}
	
	public List<T> findBy(final String propertyName, final Object value, final MatchType matchType){
		
		return entityDao.findBy(propertyName, value, matchType);
	}

	
	@Override
	public T findBy(String propertyName,Object value) {
		
		return entityDao.findUniqueBy(propertyName, value);
	}

	@Override
	public List<T> get(Collection<PK> ids) {
		
		return entityDao.get(ids);
	}

	@Autowired
	public abstract void setEntityDao(EntityDao entityDao);
	
	
}
